// ==UserScript==
// @name           Facebook at-a-glance profiles
// @url            http://userscripts.org/scripts/source/9278.user.js
// @version        1.3: Made good use of a proposed Greasemonkey improvement.
// @version        1.2: Added an indicator icon for present ICQ status, when available.
// @version        1.1: Fail silently when sex or age info was unavailable.
// @namespace      http://code.google.com/p/ecmanaut/
// @description    Decorates facebook profile names with a trailing sex/age annotation. "(M29)", for instance, signifies a 29 year old male. Also shows present ICQ status with a little icon, when listed (next to the ICQ contact info).
// @include        http://www.facebook.com/profile.php?*
// @include        http://*.facebook.com/profile.php?*
// @xpath    name: //div[@class="profile_name"]/h2
// @xpath     sex: substring(//td[@class="data"]/div/a/text()[ancestor::td[1]/preceding-sibling::td[@class="label"][.="Sex:"]],1,1)
// @xpath     age: id("Birthday")/td[@class="data"]/div/a[contains(@href,"facebook.com/b.php")]
// @xpath?    icq: //td[@class="data"]/div[../preceding-sibling::td[@class="label"][.="ICQ:"]]
// ==/UserScript==

decorate( xpath );

function decorate( profile ) {
  profile.age = profile.age.search.match(/&y1=(\d+)/)[1];
  profile.name.innerHTML += [" (", profile.sex, profile.age, ")"].join("");
  var icq = profile.icq;
  if( icq )
    icq.innerHTML = '<img style="top:1px;position:relative;" src="http://' +
      'api.oscar.aol.com/SOA/key=je1ZtapBUYJngcu0/presence/'+ icq.textContent +
      '" height="11" width="11"> '+ icq.innerHTML;
}
